package dataModifiers;

import java.util.List;

import inputs.Input;


/**
 * Abstract class for Modifiers.
 * Middle layer of flow chart.
 * Take in Inputs, run some function on them, and produce an output.
 * 
 * Abstract class - Not instantiable, but lays the framework for other concrete classes.
 * 
 * @author Dylan James
 *
 */
public abstract class Modifier extends Input{
	protected int value;
	protected List<Input> inputs;
	protected boolean run = false;
	protected int runCount = 0;
	
	protected Modifier()
	{
		super();
	}
	
	public Modifier(List<Input> inputs)
	{
		super();
		this.inputs = inputs;
		AccountForInputs();
	}
	
	public Modifier(List<Input> inputs, int min, int max)
	{
		super(min, max);
		this.inputs = inputs;
		AccountForInputs();
	}
	
	/**
	 * Called on creation of the modifier. Should do any initialization.
	 */
	protected abstract void Initialize();
	
	@Override
	public void UpdateInput(){
		if (invalid)
		{
			runCount++;
			for (Input input : inputs)
			{
				input.UpdateInput();
			}
			
			this.Update();
			this.invalid = false;
		}
	}
	
	/**
	 * 'Ticks' this modifier, causing it to update
	 */
	protected abstract void Update();
	
	/**
	 * Should be called when inputs are changed. Sets min and max values.
	 */
	protected abstract void AccountForInputs();
	
	/**
	 * Returns the current value of this modifier.
	 */
	public final int getValue() {
		return this.value;
	}
	
	/**
	 * @return Whether this modifier is in a running state
	 */
	public boolean getRun()
	{
		return this.run;
	}
	
	/**
	 * Sets whether this modifier is in a running state
	 * @param run
	 */
	public void setRun(boolean run)
	{
		if (run && !this.run)
			runCount = 0;
		this.run = run;
		
		AccountForInputs();
	}
}
